<template>
	<view>
		<u-navbar back-icon-color="#000000" :title="title" :border-bottom="false" title-color="#000000" :background="background"></u-navbar>
		<view class="top"> </view>
		<view class="content">
			<view class="up">
				<view class="list a2">
					<view class="head">
						<view class="number">
							2
						</view>
						<image :src="getHead(topList[1].head_image)" mode=""></image>
					</view>
					<view class="name">
						{{topList[1].username}}
					</view>
				</view>
				<view class="list a1">
					<view class="head">
						<view class="number">
							1
						</view>
						<image :src="getHead(topList[0].head_image)" mode=""></image>
					</view>
					<view class="name">
						{{topList[0].username}}
					</view>
				</view>
				<view class="list a3">
					<view class="head">
						<view class="number">
							3
						</view>
						<image :src="getHead(topList[2].head_image)" mode=""></image>
					</view>
					<view class="name">
						{{topList[2].username}}
					</view>
				</view>
			</view>
			<view class="down">
				<view v-if="list.length>0">
					<view class="list" v-for="(item,index) in list" :key="index">
						<view class="number">
							{{index+4}}
						</view>
						<view class="head">
							<image :src="getHead(item.head_image)" mode=""></image>
						</view>
						<view class="name">
							{{item.username}}
						</view>
					</view>
				</view>
				<view class="none" v-else>
					<view class="none-view">
						<image src="../../../static/image/none.png" class="none-image"></image>
						<view class="none-name">
							请期待更多团队~
						</view>
					</view>
				</view>
				<view class="list my">
					<view class="number" v-if="userSelf">
						{{selfa.ranking}}
					</view>
					<view class="head">
						<image :src="getHead(selfa.head_image)" mode=""></image>
					</view>
					<view class="name">
						{{userSelf ?selfa.username:'您的团队暂无排名'}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var than;
	export default {
		data() {
			return {
				background: {
					'background': '#FFD023'
				},
				title: "完成榜",
				page: 1,
				list: [{
					head_image: ''
				}],
				topList: [{
					head_image: ''
				}, {
					head_image: ''
				}, {
					head_image: ''
				}],
				userSelf: false,
				selfa: {}
			}
		},
		onLoad(option) {
			than = this;
			than.getList()
		},
		onReachBottom() {
			than.page++;
			than.getList()
		},
		methods: {
			getList() {
				var apply_type = parseInt(than.current) + 1
				than.post("api/groupwork_small/finshList", {
					page: than.page
				}, function(data) {
					if (than.checkDataNull(data.self)) {
						than.selfa = data.self
						than.userSelf = true
					} else {
						than.userSelf = false
					}

					if (than.page == 1) {
						if (data.list.length < 3) {
							switch (data.list.length) {
								case 2:
									data.list.push({
										head_image: '../static/g7.png',
										username: '暂无团队'
									})
									break;
								case 1:
									for (let i = 0; i < 2; i++) {
										data.list.push({
											head_image: '../static/g7.png',
											username: '暂无团队'
										})
									}
									break;
								default:
									for (let i = 0; i < 3; i++) {
										data.list.push({
											head_image: '../static/g7.png',
											username: '暂无团队'
										})
									}
									break;
							}
						}
						than.topList = data.list.slice(0, 3);
						than.list = data.list.splice(3, data.list.length);
					} else {
						than.list = than.list.concat(data.list)
					}
				})
			}
		}
	}
</script>

<style lang="less">
	.top {
		background: #FFD023;
	}

	.content {
		width: 100%;
		z-index: 1;

		.up {
			display: flex;
			justify-content: center;
			position: relative;
			background: #FFD023;

			.list {
				width: 226rpx;
				height: 336rpx;
				border-radius: 10rpx;
				text-align: center;

				.head {
					margin: 32rpx auto 0;
					position: relative;
					width: 124rpx;
					height: 124rpx;
					border-radius: 50%;
					display: flex;
					align-items: center;
					justify-content: center;

					.number {
						position: absolute;
						z-index: 10;
						display: flex;
						align-items: center;
						justify-content: center;
						bottom: -10rpx;
						width: 30rpx;
						height: 30rpx;
						border-radius: 50%;
						font-size: 23rpx;
						font-family: DINCond-Black;
						font-weight: 400;
					}

					image {
						width: 120rpx;
						height: 120rpx;
						border-radius: 50%;
					}
				}

				.name {
					margin-top: 25rpx;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #222222;
				}

				.text {
					margin-top: 15rpx;
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #666678;
				}
			}


			.a1 {
				background: linear-gradient(0deg, #FFF1F1, #FFFFFF);

				.head {
					.number {
						background: #222222;
						color: #BF8E4D;
					}

					background: #E7C496;
				}

				.name {
					margin-top: 65rpx;
				}
			}

			.a2 {
				margin-top: 45rpx;
				background: linear-gradient(0deg, #F1F7FF, #FFFFFF);

				.head {
					.number {
						background: #EEEEEE;
						color: #4D5272;
					}

					background: #DCDCDC;
				}
			}

			.a3 {
				margin-top: 45rpx;
				background: linear-gradient(0deg, #FEF1FF, #FFFFFF);

				.head {
					.number {
						background: #F2D6C6;
						color: #8D3E18;
					}

					background: #D9A990;
				}
			}
		}

		.down {
			border-radius: 70rpx 0rpx 0rpx 0rpx;
			background: #FFFFFF;
			z-index: 10;
			position: relative;
			margin-top: -50rpx;

			.my {
				position: fixed;
				bottom: 0;
				width: 100%;
				z-index: 20;
				background: #E5EDFC;

				.number {
					color: #C61F19 !important;
				}
			}

			.list {
				height: 117rpx;
				display: flex;
				align-items: center;

				.number {
					font-size: 36rpx;
					font-family: DIN Black;
					font-weight: 400;
					color: #A3A6B7;
					margin-left: 24rpx;
					text-align: center;
				}

				.head {
					margin-right: 24rpx;
					border-radius: 50%;
					margin-left: 24rpx;

					image {
						border-radius: 50%;
						width: 78rpx;
						height: 78rpx;
					}
				}

				.name {
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #222222;
				}

				.text {
					margin-left: auto;
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #666666;
					margin-right: 47rpx;
				}

			}
		}
	}
</style>
